    <!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('租户信息')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
<!--                            <li>-->
<!--                                <label>楼栋ID：</label>-->
<!--                                <input type="text" name="buildingId"/>-->
<!--                            </li>-->
                            <li>
                                <label>楼栋：</label>
                                <input type="text" name="buildingName"/>
                            </li>
<!--                            <li>-->
<!--                                <label>单元ID数组：</label>-->
<!--                                <input type="text" name="unitIdStr"/>-->
<!--                            </li>-->
                            <li>
                                <label>单元号：</label>
                                <input type="text" name="unitNameStr"/>
                            </li>
<!--                            <li>-->
<!--                                <label>租户用途：</label>-->
<!--                                <input type="text" name="tenantUse"/>-->
<!--                            </li>-->
                            <li>
                                <label>租户名称：</label>
                                <input type="text" name="tenantName"/>
                            </li>
                            <li>
                                租户状态：<select id="tenantStatus" name="tenantStatus" th:with="type=${@dict.getType('sys_tenant_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                            </li>

<!--                            <li>-->
<!--                                <label>租户面积：</label>-->
<!--                                <input type="text" name="tenantArea"/>-->
<!--                            </li>-->
<!--                            <li class="select-time">-->
<!--                                <label>租户起租时间：</label>-->
<!--                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginStartTime]"/>-->
<!--                                <span>-</span>-->
<!--                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endStartTime]"/>-->
<!--                            </li>-->
<!--                            <li class="select-time">-->
<!--                                <label>租户到期时间：</label>-->
<!--                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginEndTime]"/>-->
<!--                                <span>-</span>-->
<!--                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endEndTime]"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>租户状态：</label>-->
<!--                                <select name="tenantStatus">-->
<!--                                    <option value="">所有</option>-->
<!--                                    <option value="-1">代码生成请选择字典属性</option>-->
<!--                                </select>-->
<!--                            </li>-->
<!--                            <li class="select-time">-->
<!--                                <label>租金起算日：</label>-->
<!--                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginRentStartDay]"/>-->
<!--                                <span>-</span>-->
<!--                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endRentStartDay]"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>张租次数：</label>-->
<!--                                <input type="text" name="risePriceNumber"/>-->
<!--                            </li>-->
<!--                            <li class="select-time">-->
<!--                                <label>首次张租时间：</label>-->
<!--                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginRisePriceFirstTime]"/>-->
<!--                                <span>-</span>-->
<!--                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endRisePriceFirstTime]"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>涨租比率：</label>-->
<!--                                <input type="text" name="risePriceRatio"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>张租状态：</label>-->
<!--                                <select name="risePriceStatus">-->
<!--                                    <option value="">所有</option>-->
<!--                                    <option value="-1">代码生成请选择字典属性</option>-->
<!--                                </select>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>押金：</label>-->
<!--                                <input type="text" name="pledgeFee"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>装修押金：</label>-->
<!--                                <input type="text" name="decorationPledgeFee"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>月租：</label>-->
<!--                                <input type="text" name="monthlyRentFee"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>物业费：</label>-->
<!--                                <input type="text" name="propertyFee"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>清理垃圾费：</label>-->
<!--                                <input type="text" name="scavengingFee"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>水电费：</label>-->
<!--                                <input type="text" name="utilityFee"/>-->
<!--                            </li>-->
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:tenant:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:tenant:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:tenant:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
<!--                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:tenant:export">-->
<!--                    <i class="fa fa-download"></i> 导出-->
<!--                </a>-->
                <a class="btn btn-warning" onclick="exportTenantExcel('living')" shiro:hasPermission="system:tenant:exportLiving">
                    <i class="fa fa-download"></i> 导出在租合同
                </a>
                <a class="btn btn-warning" onclick="exportTenantExcel('leave')" shiro:hasPermission="system:tenant:exportLeave">
                    <i class="fa fa-download"></i> 导出退租合同
                </a>
                <a class="btn btn-warning" onclick="exportTenantExcel('riseDetail')" shiro:hasPermission="system:tenant:exportRiseDetail">
                    <i class="fa fa-download"></i> 导出递增明细
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:tenant:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:tenant:remove')}]];
        var leaveFlag = [[${@permission.hasPermi('system:tenant:leave')}]];
        var detailFlag = [[${@permission.hasPermi('system:tenant:detail')}]];
        var continueFlag = [[${@permission.hasPermi('system:tenant:continue')}]];
        var tenantType = [[${@dict.getType('sys_tenant_used')}]];
        var tenantStatus = [[${@dict.getType('sys_tenant_status')}]];
        var prefix = ctx + "system/tenant";
        var exportLivingUrl =  prefix + "/exportLiving";
        var exportLeaveUrl =  prefix + "/exportLeave";
        var exportRiseDetailUrl =  prefix + "/exportRiseDetail";

        $(function() {

            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                detailUrl: prefix + "/detail/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "合同",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'tenantId',
                    title: '合同编号',
                    visible: true
                },
                // {
                //     field: 'buildingId',
                //     title: '楼栋ID'
                // },
                {
                    field: 'buildingName', 
                    title: '楼栋'
                },
                // {
                //     field: 'unitIdStr',
                //     title: '单元ID数组'
                // },
                {
                    field: 'unitNameStr', 
                    title: '单元号'
                },
                {
                    field: 'tenantUse',
                    title: '租户用途',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(tenantType, value);
                    }
                },
                {
                    field: 'tenantName', 
                    title: '租户名称'
                },
                {
                    field: 'tenantArea',
                    title: '租户面积'
                },
                {
                    field: 'startTime', 
                    title: '租户起租时间'
                },
                {
                    field: 'endTime', 
                    title: '租户到期时间'
                },
                {
                    field: 'tenantStatus', 
                    title: '租户状态',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(tenantStatus, value);
                    }
                },
                // {
                //     field: 'rentStartDay',
                //     title: '租金起算日'
                // },
                // {
                //     field: 'risePriceNumber',
                //     title: '张租次数'
                // },
                // {
                //     field: 'risePriceFirstTime',
                //     title: '首次张租时间'
                // },
                // {
                //     field: 'risePriceRatio',
                //     title: '涨租比率'
                // },
                // {
                //     field: 'risePriceStatus',
                //     title: '张租状态'
                // },
                // {
                //     field: 'pledgeFee',
                //     title: '押金'
                // },
                // {
                //     field: 'decorationPledgeFee',
                //     title: '装修押金'
                // },
                // {
                //     field: 'monthlyRentFee',
                //     title: '月租'
                // },
                // {
                //     field: 'propertyFee',
                //     title: '物业费'
                // },
                // {
                //     field: 'scavengingFee',
                //     title: '清理垃圾费'
                // },
                // {
                //     field: 'utilityFee',
                //     title: '水电费'
                // },
                // {
                //     field: 'remark',
                //     title: '备注'
                // },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        if(row.tenantStatus==2 || row.tenantStatus ==1){
                            actions.push('<a class="btn btn-success btn-xs  disabled' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.tenantId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-warning btn-xs disabled ' + continueFlag + '" href="javascript:void(0)" onclick="continueView(\'' + row.tenantId + '\')"><i class="fa fa-search"></i>续租</a> ');
                            actions.push('<a class="btn btn-warning btn-xs  disabled' + leaveFlag + '" href="javascript:void(0)" onclick="leaveView(\'' + row.tenantId + '\')"><i class="fa fa-search"></i>离租</a> ');
                        }else {
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.tenantId + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-warning btn-xs ' + continueFlag + '" href="javascript:void(0)" onclick="continueView(\'' + row.tenantId + '\')"><i class="fa fa-search"></i>续租</a> ');
                            actions.push('<a class="btn btn-warning btn-xs' + leaveFlag + '" href="javascript:void(0)" onclick="leaveView(\'' + row.tenantId + '\')"><i class="fa fa-search"></i>离租</a> ');
                        }
                        actions.push('<a class="btn btn-info btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.tenantId + '\')"><i class="fa fa-search"></i>详情</a>');
                        actions.push('<a class="btn btn-danger btn-xs  ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.tenantId + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);

        });

        function leaveView(tenantId){
            var url = prefix + "/leave/{id}";
            var leaveUrl = url.replace("{id}", tenantId);
            $.modal.openTab("租户离租",leaveUrl);
        }

        function continueView(tenantId){
            var url = prefix + "/continue/{id}";
            var leaveUrl = url.replace("{id}", tenantId);
            $.modal.openTab("租户续租",leaveUrl);
        }

        // 导出合同数据
        function exportTenantExcel(url) {
            var exportUrl;
            if(url == 'living'){
                exportUrl = exportLivingUrl;
            } else if(url == 'leave'){
                exportUrl = exportLeaveUrl;
            }else{
                exportUrl = exportRiseDetailUrl;
            }
            table.set();
            $.modal.confirm("确定导出所有" + table.options.modalName + "吗？", function() {
                var currentId = $('form').attr('id');
                var params = $("#" + table.options.id).bootstrapTable('getOptions');
                var dataParam = $("#" + currentId).serializeArray();
                dataParam.push({ "name": "orderByColumn", "value": params.sortName });
                dataParam.push({ "name": "isAsc", "value": params.sortOrder });
                $.modal.loading("正在导出数据，请稍后...");
                $.post(exportUrl, dataParam, function(result) {
                    if (result.code == web_status.SUCCESS) {
                        window.location.href = ctx + "common/download?fileName=" + encodeURI(result.msg) + "&delete=" + true;
                    } else if (result.code == web_status.WARNING) {
                        $.modal.alertWarning(result.msg)
                    } else {
                        $.modal.alertError("无数据导出");
                    }
                    $.modal.closeLoading();
                });
            });
        }
    </script>
</body>
</html>